﻿//********************************************************************************//
//创建日期：<创建日期，2010-08-02>
//创建作者：<王一飞，wangyifei@shanghai3h.com>
//功能说明：QS_YH_YONGHUSBGX实体层次
//********************************************************************************//
#region Entity
namespace Entity
{
    using System;
    using System.Xml;
    [Serializable()]
    public class QS_YH_YONGHUSBGX
    {

        private decimal m_dec_id;
        /// <summary>
        /// 主键
        /// </summary>
        public decimal ID { get { return m_dec_id; } set { m_dec_id = value; } }

        private string m_str_s_yonghuh;
        /// <summary>
        /// 用户号
        /// </summary>
        public string S_YONGHUH { get { return m_str_s_yonghuh; } set { m_str_s_yonghuh = value; } }

        private string m_str_s_shuibiaoh;
        /// <summary>
        /// 水表号
        /// </summary>
        public string S_SHUIBIAOH { get { return m_str_s_shuibiaoh; } set { m_str_s_shuibiaoh = value; } }

        private decimal? m_dec_i_jlzt;
        /// <summary>
        /// 记录状态
        /// </summary>
        public decimal? I_JLZT { get { return m_dec_i_jlzt; } set { m_dec_i_jlzt = value; } }

        private string m_str_s_tianjiar;
        /// <summary>
        /// 添加人
        /// </summary>
        public string S_TIANJIAR { get { return m_str_s_tianjiar; } set { m_str_s_tianjiar = value; } }

        private DateTime? m_DT_d_tianjiarq;
        /// <summary>
        /// 添加日期
        /// </summary>
        public DateTime? D_TIANJIARQ { get { return m_DT_d_tianjiarq; } set { m_DT_d_tianjiarq = value; } }

        private string m_str_s_caozuor;
        /// <summary>
        /// 操作人
        /// </summary>
        public string S_CAOZUOR { get { return m_str_s_caozuor; } set { m_str_s_caozuor = value; } }

        private DateTime? m_DT_d_caozuorq;
        /// <summary>
        /// 操作日期
        /// </summary>
        public DateTime? D_CAOZUORQ { get { return m_DT_d_caozuorq; } set { m_DT_d_caozuorq = value; } }

        private string m_str_s_kaishiny;
        /// <summary>
        /// 开始年月
        /// </summary>
        public string S_KAISHINY { get { return m_str_s_kaishiny; } set { m_str_s_kaishiny = value; } }

        private string m_str_s_jieshuny;
        /// <summary>
        /// 结束年月
        /// </summary>
        public string S_JIESHUNY { get { return m_str_s_jieshuny; } set { m_str_s_jieshuny = value; } }

        private string m_str_s_beizhu;
        /// <summary>
        /// 备注
        /// </summary>
        public string S_BEIZHU { get { return m_str_s_beizhu; } set { m_str_s_beizhu = value; } }
        public QS_YH_YONGHUSBGX()
        {
        }
    }
}
#endregion
#region EntityProcess
namespace BLL.Access
{
    using System;
    using System.Data;
    //using System.Data.OracleClient;
    using Entity;
    using System.Configuration;
    using System.Data.Common;
    using Platform.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    using Oracle.DataAccess;
    public class QS_YH_YONGHUSBGXProcess
    {
        #region Field
        protected string conn;
        #endregion
        #region Construction
        public QS_YH_YONGHUSBGXProcess() { conn = Platform.Configuration.ConfigHelper.PlatformConnString; }
        #endregion
        #region public

        /// <summary>
        /// 根据QS_YH_YONGHUSBGX实体添加或者修改QS_YH_YONGHUSBGX信息
        /// </summary>
        public bool InsertOrUpdate(QS_YH_YONGHUSBGX QS_YH_YONGHUSBGX, OracleTransaction Transaction)
        {
            if (QS_YH_YONGHUSBGX.ID == 0)
            {
                InsertQS_YH_YONGHUSBGX(QS_YH_YONGHUSBGX, Transaction);
            }
            else
            {
                UpdateQS_YH_YONGHUSBGX(QS_YH_YONGHUSBGX, Transaction);
            }
            return QS_YH_YONGHUSBGX.ID == 0 ? false : true;
        }

        /// <summary>
        /// 根据QS_YH_YONGHUSBGX实体添加或修改QS_YH_YONGHUSBGX信息
        /// </summary>
        public bool InsertOrUpdate(QS_YH_YONGHUSBGX QS_YH_YONGHUSBGX)
        {
            return InsertOrUpdate(QS_YH_YONGHUSBGX, null);
        }



        /// <summary>
        /// 根据QS_YH_YONGHUSBGX主键删除QS_YH_YONGHUSBGX信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteQS_YH_YONGHUSBGX(decimal ID, OracleTransaction Transaction)
        {
            string spName = "CS_DelQS_YH_YONGHUSBGX";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            int result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        /// 根据QS_YH_YONGHUSBGX主键删除QS_YH_YONGHUSBGX信息
        /// </summary>
        /// <param name="ID"></param>
        public bool DeleteQS_YH_YONGHUSBGX(decimal ID)
        {
            return DeleteQS_YH_YONGHUSBGX(ID, null);
        }

        /// <summary>
        /// 根据条件删除QS_YH_YONGHUSBGX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteQS_YH_YONGHUSBGXesDynamic(string WhereClause, OracleTransaction Transaction)
        {
            string spName = "CS_DelQS_YH_YONGHUSBGXesDyn";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = WhereClause;
            int result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }

        /// <summary>
        /// 根据条件删除QS_YH_YONGHUSBGX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(Oracle语句)不带where</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>如果删除成功，返回true,否则返回fals</returns>
        public bool DeleteQS_YH_YONGHUSBGXesDynamic(string WhereClause)
        {
            return DeleteQS_YH_YONGHUSBGXesDynamic(WhereClause, null);
        }

        /// <summary>
        /// 根据QS_YH_YONGHUSBGX主键选择QS_YH_YONGHUSBGX信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>QS_YH_YONGHUSBGX信息</returns>
        public QS_YH_YONGHUSBGX SelectQS_YH_YONGHUSBGX(decimal ID, OracleTransaction Transaction)
        {
            string spName = "CS_SelQS_YH_YONGHUSBGX";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = ID;
            OracleDataReader rd;
            if (Transaction == null)
                rd = OracleHelper.ExecuteReader(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                rd = OracleHelper.ExecuteReader((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (rd.Read())
            {
                QS_YH_YONGHUSBGX QS_YH_YONGHUSBGX = PopulateQS_YH_YONGHUSBGX(rd);
                rd.Close();
                return QS_YH_YONGHUSBGX;
            }
            else
                return null;
        }

        /// <summary>
        /// 根据QS_YH_YONGHUSBGX主键选择QS_YH_YONGHUSBGX信息
        /// </summary>
        /// <returns>QS_YH_YONGHUSBGX信息</returns>
        public QS_YH_YONGHUSBGX SelectQS_YH_YONGHUSBGX(decimal ID)
        {
            return SelectQS_YH_YONGHUSBGX(ID, null);
        }

        /// <summary>
        /// 选择所有QS_YH_YONGHUSBGX信息
        /// </summary>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>所有QS_YH_YONGHUSBGX信息</returns>
        public DataTable SelectQS_YH_YONGHUSBGXesAll(OracleTransaction Transaction)
        {
            string spName = "CS_SelQS_YH_YONGHUSBGXesAll";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            else
                return null;
        }

        /// <summary>
        /// 选择所有QS_YH_YONGHUSBGX信息
        /// </summary>
        /// <returns>所有QS_YH_YONGHUSBGX信息</returns>
        public DataTable SelectQS_YH_YONGHUSBGXesAll()
        {
            return SelectQS_YH_YONGHUSBGXesAll(null);
        }

        /// <summary>
        /// 根据条件选择QS_YH_YONGHUSBGX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>QS_YH_YONGHUSBGX信息</returns>
        public DataTable SelectQS_YH_YONGHUSBGXesDynamic(string WhereClause, string OrderByExpression, OracleTransaction Transaction)
        {
            string spName = "CS_SelQS_YH_YONGHUSBGXesDyn";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            else
                return null;
        }


        /// <summary>
        /// 根据条件选择QS_YH_YONGHUSBGX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <returns>QS_YH_YONGHUSBGX信息</returns>
        public DataTable SelectQS_YH_YONGHUSBGXesDynamic(string WhereClause, string OrderByExpression)
        {
            return SelectQS_YH_YONGHUSBGXesDynamic(WhereClause, OrderByExpression, null);
        }



        /// <summary>
        /// 根据条件选择QS_YH_YONGHUSBGX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <param name="Transaction">事务，如果为null,则不做事务</param>
        /// <returns>QS_YH_YONGHUSBGX信息</returns>
        public DataTable SelectQS_YH_YONGHUSBGXesDynamic(string WhereClause, string OrderByExpression, int PageIndex, int PageSize, OracleTransaction Transaction)
        {
            string spName = "CS_SelQS_YH_YONGHUSBGXesDynPaged";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = string.IsNullOrEmpty(WhereClause.Trim()) ? "1=1" : WhereClause;
            storedParams[1].Value = OrderByExpression;
            storedParams[2].Value = PageIndex;
            storedParams[3].Value = PageSize;
            DataSet ds = null;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            if (ds != null && ds.Tables.Count > 0)
            {
                AddRowNumber(ds.Tables[0]);
                return ds.Tables[0];
            }
            else
                return null;
        }


        /// <summary>
        /// 根据条件选择QS_YH_YONGHUSBGX信息
        /// </summary>
        /// <param name="WhereClause">条件子句(不带where)</param>
        /// <param name="OrderByExpression">排序子句</param>
        /// <param name="PageIndex">页码</param>
        /// <param name="PageSize">页数</param>
        /// <returns>QS_YH_YONGHUSBGX信息</returns>
        public DataTable SelectQS_YH_YONGHUSBGXesDynamic(string WhereClause, string OrderByExpression, int PageIndex, int PageSize)
        {
            return SelectQS_YH_YONGHUSBGXesDynamic(WhereClause, OrderByExpression, PageIndex, PageSize, null);
        }

        /// <summary>
        ///根据条件更新QS_YH_YONGHUSBGX字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateQS_YH_YONGHUSBGXesDynamic(string UpdateValue, string WhereClause, OracleTransaction Transaction)
        {
            int result = 0;
            if (UpdateValue == "" || WhereClause == "")
            {
                return 0;
            }
            string spName = "CS_UpdQS_YH_YONGHUSBGXDyn";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            DataSet ds = null;
            storedParams[0].Value = UpdateValue;
            storedParams[1].Value = WhereClause;
            if (Transaction == null)
                ds = OracleHelper.ExecuteDataset(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                ds = OracleHelper.ExecuteDataset((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            result = Convert.ToInt32(storedParams[2].Value);
            return result;
        }

        /// <summary>
        ///根据条件更新QS_YH_YONGHUSBGX字段
        /// </summary>
        /// <returns>受影响行数</returns>
        public int UpdateQS_YH_YONGHUSBGXesDynamic(string UpdateValue, string WhereClause)
        {
            return UpdateQS_YH_YONGHUSBGXesDynamic(UpdateValue, WhereClause, null);
        }


        #endregion
        #region Private

        private int InsertQS_YH_YONGHUSBGX(QS_YH_YONGHUSBGX QS_YH_YONGHUSBGX, OracleTransaction Transaction)
        {
            string spName = "CS_InsQS_YH_YONGHUSBGX";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = QS_YH_YONGHUSBGX.S_YONGHUH;
            storedParams[1].Value = QS_YH_YONGHUSBGX.S_SHUIBIAOH;
            storedParams[2].Value = QS_YH_YONGHUSBGX.I_JLZT;
            storedParams[3].Value = QS_YH_YONGHUSBGX.S_TIANJIAR;
            storedParams[4].Value = QS_YH_YONGHUSBGX.D_TIANJIARQ;
            storedParams[5].Value = QS_YH_YONGHUSBGX.S_CAOZUOR;
            storedParams[6].Value = QS_YH_YONGHUSBGX.D_CAOZUORQ;
            storedParams[7].Value = QS_YH_YONGHUSBGX.S_KAISHINY;
            storedParams[8].Value = QS_YH_YONGHUSBGX.S_JIESHUNY;
            storedParams[9].Value = QS_YH_YONGHUSBGX.S_BEIZHU;
            int result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            QS_YH_YONGHUSBGX.ID = Convert.ToInt32(storedParams[10].Value);
            return result;
        }
        private bool UpdateQS_YH_YONGHUSBGX(QS_YH_YONGHUSBGX QS_YH_YONGHUSBGX, OracleTransaction Transaction)
        {
            string spName = "CS_UpdQS_YH_YONGHUSBGX";
            OracleParameter[] storedParams = OracleHelperParameterCache.GetSpParameterSet(conn, spName);
            storedParams[0].Value = QS_YH_YONGHUSBGX.S_YONGHUH;
            storedParams[1].Value = QS_YH_YONGHUSBGX.S_SHUIBIAOH;
            storedParams[2].Value = QS_YH_YONGHUSBGX.I_JLZT;
            storedParams[3].Value = QS_YH_YONGHUSBGX.S_TIANJIAR;
            storedParams[4].Value = QS_YH_YONGHUSBGX.D_TIANJIARQ;
            storedParams[5].Value = QS_YH_YONGHUSBGX.S_CAOZUOR;
            storedParams[6].Value = QS_YH_YONGHUSBGX.D_CAOZUORQ;
            storedParams[7].Value = QS_YH_YONGHUSBGX.S_KAISHINY;
            storedParams[8].Value = QS_YH_YONGHUSBGX.S_JIESHUNY;
            storedParams[9].Value = QS_YH_YONGHUSBGX.S_BEIZHU;
            storedParams[10].Value = QS_YH_YONGHUSBGX.ID;
            int result = 0;
            if (Transaction == null)
                result = OracleHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, spName, storedParams);
            else
                result = OracleHelper.ExecuteNonQuery((OracleTransaction)Transaction, CommandType.StoredProcedure, spName, storedParams);
            return result == 0 ? false : true;
        }


        private QS_YH_YONGHUSBGX PopulateQS_YH_YONGHUSBGX(IDataReader dr)
        {
            QS_YH_YONGHUSBGX QS_YH_YONGHUSBGX = new QS_YH_YONGHUSBGX();
            QS_YH_YONGHUSBGX.ID = dr["ID"] == DBNull.Value ? (decimal)0 : (decimal)dr["ID"];
            QS_YH_YONGHUSBGX.S_YONGHUH = dr["S_YONGHUH"] == DBNull.Value ? null : (string)dr["S_YONGHUH"];
            QS_YH_YONGHUSBGX.S_SHUIBIAOH = dr["S_SHUIBIAOH"] == DBNull.Value ? null : (string)dr["S_SHUIBIAOH"];
            QS_YH_YONGHUSBGX.I_JLZT = dr["I_JLZT"] == DBNull.Value ? null : (decimal?)dr["I_JLZT"];
            QS_YH_YONGHUSBGX.S_TIANJIAR = dr["S_TIANJIAR"] == DBNull.Value ? null : (string)dr["S_TIANJIAR"];
            QS_YH_YONGHUSBGX.D_TIANJIARQ = dr["D_TIANJIARQ"] == DBNull.Value ? null : (DateTime?)dr["D_TIANJIARQ"];
            QS_YH_YONGHUSBGX.S_CAOZUOR = dr["S_CAOZUOR"] == DBNull.Value ? null : (string)dr["S_CAOZUOR"];
            QS_YH_YONGHUSBGX.D_CAOZUORQ = dr["D_CAOZUORQ"] == DBNull.Value ? null : (DateTime?)dr["D_CAOZUORQ"];
            QS_YH_YONGHUSBGX.S_KAISHINY = dr["S_KAISHINY"] == DBNull.Value ? null : (string)dr["S_KAISHINY"];
            QS_YH_YONGHUSBGX.S_JIESHUNY = dr["S_JIESHUNY"] == DBNull.Value ? null : (string)dr["S_JIESHUNY"];
            QS_YH_YONGHUSBGX.S_BEIZHU = dr["S_BEIZHU"] == DBNull.Value ? null : (string)dr["S_BEIZHU"];
            return QS_YH_YONGHUSBGX;
        }


        private void AddRowNumber(DataTable dt)
        {
            dt.Columns.Add(new DataColumn("RowNumber", typeof(int)));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i][dt.Columns.Count - 1] = i + 1;
            }
        }
        #endregion
    }
}
#endregion